package com.hualude.roadsign.controller;

import com.hualude.roadsign.dto.JsonMsgDto;
import com.hualude.roadsign.dto.PushHistoryDto;
import com.hualude.roadsign.service.PushHistoryService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/rds_pushHistoryController")
public class PushHistoryController {

    @Resource
    private PushHistoryService pushHistoryService;

    @RequestMapping("/getPushHistoryByOrgIdAndActorId")
    @ResponseBody
    public JsonMsgDto getPushHistoryByOrgIdAndActorId(Integer orgId,
                                                      String actorIds,
                                                      Integer mCount,
                                                      Integer mSize) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(pushHistoryService.getPushHistoryByOrgIdAndActorId(orgId, actorIds, mCount, mSize));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/addPushHistory")
    @ResponseBody
    public JsonMsgDto addPushHistory(PushHistoryDto pushHistoryDto) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(pushHistoryService.addPushHistory(pushHistoryDto));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getPushHistory")
    @ResponseBody
    public JsonMsgDto getAlarmPushHistory(Integer alarmType, String orgIds, String actors, Integer mCount, Integer mSize) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(pushHistoryService.getAlarmPushHistory(alarmType, orgIds, actors, mCount, mSize));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getAlarmTypeCount")
    @ResponseBody
    public JsonMsgDto getAlarmTypeCount(String limitTime, String orgIds) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(pushHistoryService.getAlarmTypeCount(limitTime, orgIds));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getFaultHistoryByOrgIdAndType")
    @ResponseBody
    public JsonMsgDto getFaultHistoryByOrgIdAndType(Integer orgId,Integer pushType,Integer mCount,Integer mSize)throws Exception{

        JsonMsgDto jsonMsgDto=new JsonMsgDto();
        try{
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(pushHistoryService.getFaultHistoryByOrgIdAndType(orgId,pushType,mCount,mSize));
        }catch (Exception e){
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;

    }

}
